package com.hulk.ratel.framework.config.properties;

import lombok.Cleanup;
import lombok.SneakyThrows;

import lombok.extern.slf4j.Slf4j;


import java.io.InputStream;
import java.util.Properties;

@Slf4j
public class PropertyUtil {

    private static Properties props;
    static {
        loadProps();
    }
    @SneakyThrows
    synchronized static private void loadProps() {
        log.debug("开始加载properties文件内容.......");
        props = new Properties();
        @Cleanup InputStream in = PropertyUtil.class.getClassLoader().getResourceAsStream("common.properties");
        props.load(in);
        log.debug("加载properties文件内容完成...........");
        log.debug("properties文件内容：" + props);
    }
    public static String getProperty(String key) {
        if (null == props) {
            loadProps();
        }
        return props.getProperty(key);
    }
    public static String getProperty(String key, String defaultValue) {
        if (null == props) {
            loadProps();
        }
        return props.getProperty(key, defaultValue);
    }
}